/*

 */

#import "UIView+Apperance.h"

@implementation UIView (Apperance)

#pragma mark - Show and Hide options

-(void) show:(BOOL)show {
    [self show:show animated:NO];
}

-(void) show:(BOOL)show
    animated:(BOOL)animated {
    
    void (^animations)() = ^(){
        if (show) {
            self.hidden = !show;
        }
        self.alpha = show;
    };
    
    void (^completionBlock)(BOOL) = ^(BOOL finished){
        
        if (!show) {
            self.hidden = !show;
        }
    };
    
    if (!animated) {
        animations();
        completionBlock(YES);
        return;
    }
    
    [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                     animations:animations
                     completion:completionBlock];
}

-(void) show:(BOOL)show
    animated:(BOOL)animated
completionBlock:(void(^)(BOOL))completion {

    void (^animations)() = ^(){
        if (show) {
            self.hidden = !show;
        }
        self.alpha = show;
    };
    
    void (^completionBlock)(BOOL) = ^(BOOL finished){
        
        if (!show) {
            self.hidden = !show;
        }
        if(completion)completion(YES);
    };
    
    if (!animated) {
        animations();
        completionBlock(YES);
        return;
    }
    
    [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                     animations:animations
                     completion:completionBlock];
}

-(void) show:(BOOL)show
    duration:(NSTimeInterval)duration
    animated:(BOOL)animated
completionBlock:(void(^)(BOOL))completion {
    
    void (^animations)() = ^(){
        if (show) {
            self.hidden = !show;
        }
        self.alpha = show;
    };
    
    void (^completionBlock)(BOOL) = ^(BOOL finished){
        
        if (!show) {
            self.hidden = !show;
        }
        if(completion)completion(YES);
    };
    
    if (!animated) {
        animations();
        completionBlock(YES);
        return;
    }
    
    [UIView animateWithDuration:duration delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                     animations:animations
                     completion:completionBlock];
}

-(void) show:(BOOL)show
    duration:(NSTimeInterval)duration
animationOptions:(UIViewAnimationOptions) options
    animated:(BOOL)animated
completionBlock:(void(^)(BOOL))completion {
    
    void (^animations)() = ^(){
        if (show) {
            self.hidden = !show;
        }
        self.alpha = show;
    };
    
    void (^completionBlock)(BOOL) = ^(BOOL finished){
        
        if (!show) {
            self.hidden = !show;
        }
        if(completion)completion(YES);
    };
    
    if (!animated) {
        animations();
        completionBlock(YES);
        return;
    }
    
    [UIView animateWithDuration:duration delay:0.0 options:options
                     animations:animations
                     completion:completionBlock];
}

#pragma mark - Frames

-(void) setFrame:(CGRect)frame
        animated:(BOOL) animated {
    
    
    void (^animations)() = ^(){
        self.frame = frame;
    };
    
    if (!animated) {
        animations();
        return;
    }
    
    [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                     animations:animations
                     completion:nil];
}

-(void) setFrame:(CGRect)frame
        animated:(BOOL)animated
 completionBlock:(void(^)(BOOL))completion {
    
    
    void (^animations)() = ^(){
        self.frame = frame;
    };
    
    if (!animated) {
        animations();
        completion(YES);
        return;
    }
    
    [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                     animations:animations
                     completion:completion];
}

-(void) setFrame:(CGRect)frame
        duration:(NSTimeInterval)duration
        animated:(BOOL)animated
 completionBlock:(void(^)(BOOL))completion {
    
    
    void (^animations)() = ^(){
        self.frame = frame;
    };
    
    if (!animated) {
        animations();
        completion(YES);
        return;
    }
    
    [UIView animateWithDuration:duration delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                     animations:animations
                     completion:completion];
}

-(void) setFrame:(CGRect)frame
        duration:(NSTimeInterval)duration
    animationOptions:(UIViewAnimationOptions) options
        animated:(BOOL)animated
 completionBlock:(void(^)(BOOL))completion {
 
    
    void (^animations)() = ^(){
        self.frame = frame;
    };
    
    if (!animated) {
        animations();
        completion(YES);
        return;
    }
    
    [UIView animateWithDuration:duration delay:0.0 options:options
                     animations:animations
                     completion:completion];
}
@end
